
fromServSocket.onmessage = function(event) {
    var msg = $.parseJSON(event.data);
    if (msg.type == "ChannelMessage") {
        $("#chat-msg-area").append("" +
            "<div class='chat-in'>" +
                "<span class='chat-time'></span>" +
                 "<strong class='chat-user'>" + msg.from + "</strong>"+
                 "<div class='chat-text'>" + msg.text + "</div>" +
            "</div>");
    }

    if (msg.type == "ChangeStatusMessage") {
        var user = msg.user;
        var status = msg.status;
        var userStatusSelector = $("#status_" + user);
        userStatusSelector.removeAttr('class');
        userStatusSelector.attr('class', 'icofont-certificate color-'+ status);
    }

    if (msg.type == "MemberJoinedChannelMessage") {
        $("#contact-list").append(
            "<li class='contact-alt grd-white'>" +
                "<a href='#'>" +
                    "<div class='contact-item'>" +
                        "<div class='pull-left'>" +
                            "<img class='contact-item-object' style='width: 32px;height: 32px;' src='/public/img/user-thumb-mini.jpg'>" +
                        "</div>" +
                        "<div class='contact-item-body'>" +
                            "<div class='status' title='busy'><i id='status_" + msg.name +"' class='icofont-certificate color-"+ msg.status +"'></i></div>" +
                            "<p class='contact-item-heading bold'>" + msg.name + "</p>" +
                            "<p class='help-block'><small class='muted'>project user</small></p>" +
                        "</div>" +
                    "</div>" +
                "</a>" +
            "</li>");
    }

    if (msg.type == "MemberLeftChannelMessage") {
        $("#status_" + msg.name).closest("li").remove();
    }

    //$("#empty").before("<p> <span style='color: blue'> " + msg.from + "</span>&gt&nbsp" + msg.text + "</p>");
};
toServSocket.onmessage = function(event) {
};

function sendMessage() {
    var message = $("#message_text").val();
    toServSocket.send(message);
    $("#message_text").val("");
}
